#include "./moveable_win.h"

void MoveableWin::mousePressEvent(QMouseEvent *event) {
    if (event->button() == Qt::LeftButton) {
        m_is_pressed = true;
        m_drag_position = event->globalPos() - frameGeometry().topLeft();
        event->accept();
        return;
    }
    return QWidget::mousePressEvent(event);
}

void MoveableWin::mouseMoveEvent(QMouseEvent *event) {
    if (m_is_pressed && (event->buttons() & Qt::LeftButton)) {
        move(event->globalPos() - m_drag_position);
        event->accept();
        return;
    }
    return QWidget::mouseMoveEvent(event);
}

void MoveableWin::mouseReleaseEvent(QMouseEvent *event) {
    if (event->button() == Qt::LeftButton) {
        m_is_pressed = false;
    }
}
